import { type PaginationProps } from "@pureadmin/table";

import { ref, computed, Transition, reactive, onMounted, nextTick } from "vue";
import { ElMessage } from "element-plus";
import { Pie } from '@antv/g2plot';
import { useRoute } from "vue-router";
import {
  SuperviseRiskMonitorRiskMonitorList,
  SuperviseRiskMonitorRiskMonitorChart,
  SuperviseRiskMonitorRiskMonitorBaseData
} from "@/api/stu/FinancialSupervision";
export function useFXhooks(models) {
  const route = useRoute();
  const dataList = ref();
  const ModelDataList = ref();
  const risky = ref(0);
  const riskfree = ref(0)
  const loading = ref<boolean>(false);
  const submissionName = ref('');
  // 反洗钱监控中心
  const columns: TableColumnList = [
    {
      label: "序号",
      type: "index",
      minWidth: 100
    },
    {
      label: "姓名",
      prop: "name",
    },
    {
      label: "性别",
      prop: "gender",
    },
    {
      label: "年龄",
      prop: "age",
    },
    {
      label: "民族",
      prop: "nation",
    },
    {
      label: "身份证号",
      prop: "idCard",
    },
    {
      label: "电话号码",
      prop: "phone",
    },
    {
      label: "电子邮件",
      prop: "email",
    },
    {
      label: "婚姻状况",
      prop: "marriage",
    },
    {
      label: "省份",
      prop: "province",
    },
    {
      label: "家庭住址",
      prop: "homeAddress",
    },

    {
      label: "IP地址",
      prop: "ipAddress",
    },
    {
      label: "教育程度",
      prop: "educationLevel",
    },
    {
      label: "单位性质",
      prop: "job",
    },
    {
      label: "职称",
      prop: "competent",
    },
    {
      label: "年收入（元）",
      prop: "annualIncome",
      width: 100
    },
    {
      label: "月收入（元）",
      prop: "mothlyIncome",
      width: 100
    },
    {
      label: "身体状况",
      prop: "health",
    },
    {
      label: "担保方式",
      prop: "guaranteeMode",
    },
    {
      label: "分期付款占月收入的比重",
      prop: "installmentRate",
      width: 200
    },
    {
      label: "贷款期限",
      prop: "loanTerm",
    },
    {
      label: "逾期次数",
      prop: "overdueTimes",
    },

    /*  {
        label: "用户信息ID",
        prop: "personalInformationId",
      },*/
    {
      label: "交易频率（次/天）",
      prop: "jyzZ_JYPL",
      width: 200
    },
    {
      label: "交易IP地址分布区域",
      prop: "jyzZ_JYIPFB",
    },
    {
      label: "同一IP地址对不同客户之间的单日最多交易次数",
      prop: "jyzZ_IPJY",
      width: 200
    },
    {
      label: "单笔最大交易金额（元）",
      prop: "jyzZ_DBZDJYJE",
      width: 120
    },
    {
      label: "交易双方账户类型",
      prop: "jyzZ_JYZHLX",
    },
    {
      label: "交易双方账户开户地",
      prop: "jyzZ_JYZHKHD",
    },


    {
      label: "代理交易次数（次/天）",
      prop: "jyzZ_DLJYCS",
      width: 100
    },
    {
      label: "单笔最大保费金额",
      prop: "bX_DBZDJE",
    },
    {
      label: "投保频率（次/天）",
      prop: "bX_TBPL",
    }, {
      label: "退保频率（次/天）",
      prop: "bX_TIBPL",
    },

    {
      label: "申请保单质押贷款金额（元）",
      prop: "bX_DKJE",
      width: 110
    },
    {
      label: "申请保单质押贷款频率（次/天）",
      prop: "bX_DKPL",
      width: 120
    },
    {
      label: "生存保险受益人更换频率（次/天）",
      prop: "bX_SYRGHPL",
      width: 120
    },
    {
      label: "万能险追加保费金额（元）",
      prop: "bX_ZJBFJE",
      width: 180
    },
    {
      label: "万能险追加保费频率（次/天）",
      prop: "bX_ZJBFPL",
      width: 120
    },
    {
      label: "购买信托产品金额（元）",
      prop: "xT_CPJE",
      width: 180
    },
    {
      label: "购买信托产品频率（次/天）",
      prop: "xT_CPPL",
      width: 140
    },
    {
      label: "证券交易频率（次/天）",
      prop: "zQ_JYPL",
      width: 160
    },
    {
      label: "证券单笔最大交易金额",
      prop: "zQ_DBZDJE",
    },
    {
      label: "期货交易频率（次/天）",
      prop: "qH_JYPL",
      width: 200
    }, {
      label: "单笔最大期货交易金额（元）",
      prop: "qH_DBZDJYJE",
      width: 120
    },
    {
      label: "是否大宗交易",
      prop: "qH_SFDZJY",
      width: 140
    },
    {
      label: "是否交易所预警交易",
      prop: "qH_SFJYSYJJY",
    },
    {
      label: "单笔最大套现金额（元）",
      prop: "qT_DBZDTXJE",
      width: 120
    },
    {
      label: "套现地区",
      prop: "qT_TXDQ",
    },
    {
      label: "紧急联系人信息相同客户数",
      prop: "qT_JJLXRXXXTKHS",
      width: 120
    },
    {
      label: "挂失频率（次/天）",
      prop: "qT_GSPL",
      width: 160
    },
    {
      label: "重置密码频率（次/天）",
      prop: "qT_CZMMPL",
      width: 200
    },
    {
      label: "身份信息状态",
      prop: "qT_SFXXZT",
      width: 120
    },
    {
      label: "反洗钱交易监测记录",
      prop: "qT_FXQJYJCJL",
    },
    {
      label: "所在行业",
      prop: "qT_SZHY",
      width: 120
    },
  ];
  // 反金融欺诈监控中心
  const columns2: TableColumnList = [
    {
      label: "序号",
      type: "index",
      minWidth: 100
    },
    {
      label: "姓名",
      prop: "name",
    },
    {
      label: "性别",
      prop: "gender",
    },
    {
      label: "年龄",
      prop: "age",
    },
    {
      label: "民族",
      prop: "nation",
    },
    {
      label: "身份证号",
      prop: "idCard",
    },
    {
      label: "电话号码",
      prop: "phone",
    },
    {
      label: "电子邮件",
      prop: "email",
    },
    {
      label: "婚姻状况",
      prop: "marriage",
    },
    {
      label: "省份",
      prop: "province",
    },
    {
      label: "IP地址",
      prop: "ipAddress",
    },
    {
      label: "教育程度",
      prop: "educationLevel",
    },
    {
      label: "单位性质",
      prop: "job",
    },
    {
      label: "职称",
      prop: "competent",
    },
    {
      label: "年收入（元）",
      prop: "annualIncome",
      width: 100
    },
    {
      label: "月收入（元）",
      prop: "mothlyIncome",
      width: 100
    },
    {
      label: "身体状况",
      prop: "health",
    },
    {
      label: "担保方式",
      prop: "guaranteeMode",
    },
    {
      label: "分期付款占月收入的比重",
      prop: "installmentRate",
      width: 200
    },
    {
      label: "贷款期限",
      prop: "loanTerm",
    },
    {
      label: "逾期次数",
      prop: "overdueTimes",
    },
    {
      label: "交易对方账户状态",
      prop: "counterpartyAccountStatus",
      width: 120
    },
    {
      label: "单笔交易最大金额（元）",
      prop: "maxAmountSingleTransaction",
      width: 200
    },
    {
      label: "非柜面交易平均金额（元）",
      prop: "avgAmountOfNonCounterTrans",
      width: 200
    },
    {
      label: "多日密码验证连续错误次数",
      prop: "consecutivePwdValidationErrors",
      width: 200
    },
    {
      label: "交易频率 （次/天）",
      prop: "transactionFrequency",
      width: 120
    },
    {
      label: "交易对方账户开户所在地",
      prop: "locationOfCounterpartyAccountOpening",
      width: 200,
    },
    {
      label: "账户登录地点",
      prop: "accountLoginLocation",
      width: 100
    },
    {
      label: "登录手机",
      prop: "loginPhone",
    },
    {
      label: "单笔最大提现金额（元）",
      prop: "maxiwithdrawalAmountSingleTrans",
      width: 200
    },
    {
      label: "是否全额提现",
      prop: "whetherToWithdrawInFull",
      width: 100
    },
    {
      label: "提现地点",
      prop: "withdrawalLocation",
    },
    {
      label: "提现手机",
      prop: "withdrawalMobilePhone",
    },
    {
      label: "交易币种",
      prop: "transactionCurrency",
    },
    {
      label: "与同一商户交易最多次数",
      prop: "maxNumberTransSameMerchant",
      width: 200,

    },
    {
      label: "注册各类账号频率 （次/天）",
      prop: "frequencyOfRegVariousAccounts",
      width: 200,

    },
    {
      label: "注册各类账号数量",
      prop: "numberOfRegVariousAccounts",
      width: 200,
    },
    {
      label: "连续身份认证失败次数",
      prop: "identityAuthFailures",
      width: 200,

    },
    {
      label: "使用同一IP地址业务申请量",
      prop: "businessApplyUseSameIpAddressNum",
      width: 200,

    },
    {
      label: "单日最高交易量",
      prop: "maxDailyTradeVolume",
      width: 120

    },
    {
      label: "注册设备关联用户数量",
      prop: "regDeviceAssociatedUsersNum",
      width: 200,

    },
    {
      label: "名下银行卡是否涉嫌欺诈",
      prop: "bankCardSuspectedOfFraud",
      width: 200,
    }, {
      label: "是否失信人员",
      prop: "whetherDishonestPersonnel",
      width: 100
    },
    {
      label: "商户手输卡号交易占比（%）",
      width: 200,
      prop: "tb",

    }
  ];
  const columns3: TableColumnList = [
    {
      label: "序号",
      type: "index",
      minWidth: 100
    },
    {
      label: "姓名",
      prop: "name",
    },
    {
      label: "性别",
      prop: "gender",
    },
    {
      label: "年龄",
      prop: "age",
    },
    {
      label: "民族",
      prop: "nation",
    },
    {
      label: "身份证号",
      prop: "idCard",
    },
    {
      label: "电话号码",
      prop: "phone",
    },
    {
      label: "电子邮件",
      prop: "email",
    },
    {
      label: "婚姻状况",
      prop: "marriage",
    },
    {
      label: "省份",
      prop: "province",
    },
    {
      label: "IP地址",
      prop: "ipAddress",
    },
    {
      label: "教育程度",
      prop: "educationLevel",
    },
    {
      label: "单位性质",
      prop: "job",
    },
    {
      label: "职称",
      prop: "competent",
    },
    {
      label: "年收入（元）",
      prop: "annualIncome",
      width: 100
    },
    {
      label: "月收入（元）",
      prop: "mothlyIncome",
      width: 100
    },
    {
      label: "身体状况",
      prop: "health",
    },
    {
      label: "企业名称",
      prop: "enterpriseName",
    },
    {
      label: "注册地址",
      prop: "registerAddress",
      width: 200
    },
    {
      label: "登记注册类型",
      prop: "registerType",
      cellRenderer: ({ row }) => (
        <el-tag type={
          row.registerType ? "danger" : "warning"}>
          {
            row.registerType ? "外商投资企业" : "内资企业"
          }
        </el-tag>
      ),
      width: 100
    },
    {
      label: "登记注册号",
      prop: "registerNo",
      width: 200
    },
    {
      label: "登记注册日期",
      prop: "registerDate",
      width: 100
    },
    {
      label: "有效截止日期",
      prop: "endDate",
      width: 100
    },
    {
      label: "组织机构代码",
      prop: "organizationCode",
      width: 100
    },
    {
      label: "中征码",
      prop: "strikeCode",
      width: 200
    },
    {
      label: "国税登记号",
      prop: "nationalTaxNo",
    },
    {
      label: "用户基本信息id",
      prop: "personalInformationId",
      width: 110
    },
    {
      label: "法人职务",
      prop: "legalJob",
    },
    {
      label: "法人姓名",
      prop: "legalName",
    },
    {
      label: "法人证件类型",
      prop: "legalCertificateType",
      width: 110
    },
    {
      label: "法人证件号码",
      prop: "legalCertificateNo",
      width: 110
    },
    {
      label: "法人联系方式",
      prop: "legalPhone",
      width: 110
    },
    {
      label: "高管最后一次交易日期与上一次交易日期时间间隔",
      prop: "recentTransactionTimeInterval",
      width: 200
    },
    {
      label: "高管是否有协议转让",
      prop: "isThereAnAgreementToTransfer",
    },
    {
      label: "是否有期权行权复杂的股权交易",
      prop: "isThereAnOptionExercised",
      width: 160
    },
    /*{
      label: "复杂的股权交易次数",
      prop: "numberOfComplexEquityTransactions",
    },*/
    {
      label: "循环交易次数",
      prop: "numberOfRecurringTransactions",
      width: 110
    },
    {
      label: "具有大额异常结构或退货的销售业务次数",
      prop: "plTa",
      width: 200
    },
    {
      label: "与境外企业之间的交易次数",
      prop: "plTb",
      width: 200
    },
    {
      label: "在合同期限届满之前变更条款的交易次数",
      prop: "plTc",
      width: 160
    },
    {
      label: "采用特殊交易模式或创新交易模式次数",
      prop: "plTd",
      width: 160
    },
    {
      label: "交易价格明显偏离正常市场价格次数",
      prop: "plTf",
      width: 160
    },
    {
      label: "交易标的对被审计单位或交易对手而言不具有合理用途次数",
      prop: "plTe",
      width: 200
    },
    {
      label: "非金额重大的衍生金融工具交易次数",
      prop: "plTg",
      width: 160
    },
  ];
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 20,
    currentPage: 1,
    pageSizes: [20, 50, 100],
    background: true
  });
  // 饼图
  const piePlot = ref();
  function ShowAntvG2Pie(data1, data2, type) {
    const data = [
      {
        type: '有风险客户数量',
        value: data1
      },
      {
        type: '无风险客户数量',
        value: data2
      }
    ];
    piePlot.value = new Pie('content', {
      appendPadding: 15,
      data,
      angleField: 'value',
      colorField: 'type',
      radius: 1,
      innerRadius: 0.60,
      meta: {
        value: {
          formatter: (v) => ` ${v}`,
        },
      },
      label: {
        type: 'inner',
        offset: '-50%',
        autoRotate: false,
        style: { textAlign: 'center' },
        formatter: ({ percent }) => `${(percent * 100).toFixed(3)}%`,
        // formatter: (percent) => {
        //   console.log("percent", percent)
        // },
      },
      statistic: {
        title: {
          content: '组合配比',
          offsetY: -8,
          style: {
            fontSize: '12',
            fontWeight: 400,
          },

        },
        content: {
          offsetY: -4,
          content: '',
          style: {
            fontSize: '12',
            fontWeight: 400,
          },
        }
      },
      interactions: [
        { type: 'element-selected' },
        { type: 'element-active' },
        {
          type: 'pie-statistic-active',
          cfg: {
            start: [
              { trigger: 'element:mouseenter', action: 'pie-statistic:change' },
              { trigger: 'legend-item:mouseenter', action: 'pie-statistic:change' },
            ],
            end: [
              { trigger: 'element:mouseleave', action: 'pie-statistic:reset' },
              { trigger: 'legend-item:mouseleave', action: 'pie-statistic:reset' },
            ],
          },
        },
      ],

    });

    piePlot.value.render();
  }
  function handleSizeChange() { GetDataList() }
  function handleCurrentChange() { GetDataList() }


  // 获取数据列表
  async function GetDataList() {
    const data = {
      pageIndex: pagination.currentPage,
      pageCount: pagination.pageSize,
      taskId: route.query.taskId,
      planId: route.query.planId,
      riskMonitorType: models,
      strategyCenterId: submissionName.value
    };
    const res = await SuperviseRiskMonitorRiskMonitorList(data);
    if (res.success) {
      dataList.value = res.data.items;
      pagination.total = res.data.totalCount;
      loading.value = false
    } else {
      ElMessage.error(res.msg);
      setTimeout(() => {
        loading.value = false
      }, 1500)
    }
  }

  async function GetModelDataList() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      riskMonitorType: models,
    };
    const res = await SuperviseRiskMonitorRiskMonitorBaseData(data);
    if (res.success) {
      ModelDataList.value = res.data;
    } else {
      ElMessage.error(res.msg);
    }
  };

  async function GetEchartsDataList() {
    const data = {
      riskMonitorType: models,
      taskId: route.query.taskId,
      planId: route.query.planId,
      strategyCenterId: submissionName.value
    };
    const res = await SuperviseRiskMonitorRiskMonitorChart(data);
    if (res.success) {
      risky.value = res.data.riskNum;
      riskfree.value = res.data.totalNum;
      // ShowAntvG2Pie(risky.value, riskfree.value, 'upadta')
      piePlot.value.update({
        data: [
          {
            type: '有风险客户数量',
            value: risky.value
          },
          {
            type: '无风险客户数量',
            value: riskfree.value
          }
        ]
      });
      piePlot.value.render();
    } else {
      ElMessage.error(res.msg);
    }
  };

  onMounted(() => {
    // GetDataList()
    GetModelDataList()
    nextTick(() => {
      ShowAntvG2Pie(risky.value, riskfree.value, 'new')
    })
  })
  return {
    risky,
    riskfree,
    dataList,
    loading,
    columns,
    columns2,
    columns3,
    pagination,
    ModelDataList,
    submissionName,
    GetDataList,
    handleSizeChange,
    GetEchartsDataList,
    handleCurrentChange,
  }
}
